package com.woniuxy.hrp.provider;

import com.woniuxy.hrp.entity.Doctor;
import org.apache.ibatis.jdbc.SQL;

public class DoctorSqlProvide {
    public  String selectDoctorByCondition(Doctor doctor) {
        String sql = new SQL() {
            {
                SELECT("*");
                FROM("hrp_doctor");
                if (doctor.getName() != null) {
                    WHERE("name = #{name}");
                }
                if (doctor.getPosition() != null && doctor.getPosition().getId() != 0) {
                    WHERE("position_id=#{position.id}");
                }
                if (doctor.getDescription() != null) {
                    WHERE("description=#{description}");
                }
                if (doctor.getDepartment() != null && doctor.getDepartment().getId() != 0) {
                    WHERE("Department_id=#{department.id}");
                }
                if (doctor.getStatus() != null) {
                    WHERE("status = #{status}");
                }
                if (doctor.getAccount() != null) {
                    WHERE("account = #{account}");
                }
                if (doctor.getId() != null) {
                    WHERE("id = #{id}");
                }
            }}.toString();
        return sql;
    }

}
